﻿using Esri.ArcGISRuntime.Mapping;
using Esri.ArcGISRuntime.UI;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;
using WRJClient.UI.Map;
using WRJClient.Common;
using WRJClient.ViewModel;
using Esri.ArcGISRuntime.Geometry;

namespace WRJClient.UI.SystemMonitor
{
    /// <summary>
    /// WorkStationView.xaml 的交互逻辑
    /// </summary>
    public partial class ControlCenterView : UserControl
    {
        private ControlCenterViewModel controlCenterViewModel;
        public ControlCenterView(ControlCenterViewModel model)
        {
            InitializeComponent();
            MapManager.Instance.Init(baseMap);
            controlCenterViewModel = model;
            body.DataContext = model;
            Loaded += ControlCenterView_Loaded;
        }

        private void loadMap()
        {
            controlCenterViewModel.AddGraphics();
            foreach (var item in WorkStationManager.Instance.Datas)
            {
                item.AddGraphics();

                //PointCollection pointCollection = new PointCollection(SpatialReferences.Wgs84);
                //pointCollection.Add(new MapPoint(item.StaticData.Longitude, item.StaticData.Latitude, SpatialReferences.Wgs84));
                //pointCollection.Add(new MapPoint(controlCenterViewModel.StaticData.Longitude, controlCenterViewModel.StaticData.Latitude, SpatialReferences.Wgs84));
                //MapManager.Instance.AddGraphic(GraphicFactory.CreateLineGraphic(item.StaticData.DbId, GraphicPart.WorkStationLink, SymbolHelper.Instance.GetLineSymbolInfo(item.GetType(), "链路"), pointCollection));
            }

            GraphicsOverlay overlay = baseMap.GetGraphicsOverlay("Layer1");
            if (overlay != null)
            {
                baseMap.SetViewPoint(overlay.Extent);
            }
        }

        private void ControlCenterView_Loaded(object sender, RoutedEventArgs e)
        {
            loadMap();
        }

    }
}
